//
//  CHJUploadTask.m
//  
//
//  Created by jiaxuzhou on 2017/12/2.
//

#import "CHJUploadTask.h"
#import "CHJSpeedCount.h"
#import "CHJUploadManager.h"
#import "CHJUploadVideo.h"

@interface CHJUploadTask ()
{
    BOOL _executing;
    BOOL _finished;
    
}

@property (assign, nonatomic, getter = isExecuting) BOOL executing;
@property (assign, nonatomic, getter = isFinished) BOOL finished;

@end

@implementation CHJUploadTask

- (void)dealloc {
    NSLog(@"=======>释放");
}

- (void)setFinished:(BOOL)finished {
    [self willChangeValueForKey:@"isFinished"];
    _finished = finished;
    [self didChangeValueForKey:@"isFinished"];
}

- (void)setExecuting:(BOOL)executing {
    [self willChangeValueForKey:@"isExecuting"];
    _executing = executing;
    [self didChangeValueForKey:@"isExecuting"];
}


- (BOOL)isConcurrent {
    return YES;
}

- (BOOL)isExecuting {
    return _executing;
}

- (BOOL)isFinished {
    return _finished;
}

- (void)finish {
    self.executing    = NO;
    self.finished     = YES;
}

- (void)checkFailure {
    if (self.lastSuccessTime) {
        self.lastSuccessTime = time(nil);
    }
    NSTimeInterval elapseTime = time(nil) - self.lastSuccessTime;
    NSLog(@"计时 %f", elapseTime);
    if (elapseTime > 60.0f) {
        self.video.uploadStatus = @"3";
        [self.uploadManager uploadFailedWithVideo:self.video];
        [self cancel];
        [self finish];
    }
}

- (void)resetCheckFailure {
    self.lastSuccessTime = time(nil);
}


@end
